package com.itheima.dao;

import com.itheima.pojo.TCategoryMenu;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CategoryMenuMapper extends Mapper<TCategoryMenu> {
    @Select("SELECT  * FROM t_category_menu WHERE menu_type= 1 OR menu_level= #{keyword} ;")
    @Results({
            @Result(property = "menuLevel", column = "menu_level"),
            @Result(property = "parentUid", column = "parent_uid"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "isShow", column = "is_show"),
            @Result(property = "menuType", column = "menu_type"),
    })
    List<TCategoryMenu> selectByMenuLevel(Integer keyword);

    @Select("SELECT MAX(sort) FROM t_category_menu; ")
    Integer getMaxSort();

    @Select("SELECT * FROM `t_category_menu` WHERE `name` =  #{keyword}  or ''= #{keyword} ")
    @Results({
            @Result(property = "menuLevel", column = "menu_level"),
            @Result(property = "parentUid", column = "parent_uid"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "isShow", column = "is_show"),
            @Result(property = "menuType", column = "menu_type"),
    })
    List<TCategoryMenu> selectByName(String keyword);
}
